//
//  BSTopicPictureView.m
//  baisibudejie
//
//  Created by 陈博文 on 15/12/27.
//  Copyright © 2015年 陈博文. All rights reserved.
//

#import "BSTopicPictureView.h"
#import <UIImageView+WebCache.h>
#import "BSTopic.h"
#import "BSSeeBigPictureViewController.h"


@interface BSTopicPictureView ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIImageView *gifPictureImageView;
@property (weak, nonatomic) IBOutlet UIButton *seeBigPictureButton;

@end

@implementation BSTopicPictureView

- (void)awakeFromNib
{
    self.imageView.userInteractionEnabled = YES;
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeBigPicture)]];
}

- (void)seeBigPicture
{
    BSSeeBigPictureViewController *seeBigPictureVc = [[BSSeeBigPictureViewController alloc] init];
    seeBigPictureVc.topic = self.topic;
    [self.window.rootViewController presentViewController:seeBigPictureVc animated:YES completion:nil];
}


-(void)setTopic:(BSTopic *)topic{
    
    _topic = topic;
    
    self.gifPictureImageView.hidden = !topic.is_gif;
    
    //对图片进行过滤
    if ((topic.isBigPicture)) {
        self.imageView.contentMode = UIViewContentModeTop;
        self.seeBigPictureButton.hidden = NO;
        self.imageView.clipsToBounds = YES;
    }else{
        self.imageView.contentMode = UIViewContentModeScaleToFill;
        self.seeBigPictureButton.hidden = YES;
        self.imageView.clipsToBounds = YES;
    }
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.image1]];

    
    //    if ([topic.image1.pathExtension.lowercaseString isEqualToString:@"gif"])
    
    // topic.image1.lowercaseString : 忽略大小写来判断
    //    if ([topic.image1.lowercaseString hasSuffix:@"gif"])
}


- (IBAction)seeBigPictureButton:(id)sender {
    
    [self seeBigPicture];
}

@end
